<?php


namespace app\admin\controller;


use app\common\controller\Adminbase;
use think\Db;

class Linkage extends Adminbase
{
    protected function initialize()
    {
        parent::initialize();
    }

    public function index()
    {
        if ($this->request->isPost()) {
            $data = $this->request->Post();
            $insert_data=array(
                'id'=>$data['id'],
                'cate_id'=>$data['cate_id'],
                'goods_id'=>$data['goods_id'],
                'gk_money'=>$data['gk_money'],
                'zhi_money'=>$data['zhi_money'],
                'jin_money'=>$data['jin_money'],
//                'buy_num'=>$data['buy_num'],
            );
            Db::name('linkage')->update($insert_data);
            $this->success('操作成功！');
        }
        $data=Db::name('linkage')->find();
        $goods=Db::name('goods')->where([
            'is_del'=>0,
            'cate_id'=>$data['cate_id']
        ])->select();
        $goods_cate=Db::name('goods_cate')->where([
            'is_del'=>0
        ])->order('sort desc')->select();
        $this->assign([
            'goods'=>$goods,
            'goods_cate'=>$goods_cate,
            'data'=>$data
        ]);
        return $this->fetch();
    }
    public function get_goods(){
        $id = input('id');
        $goods_list=Db::name('goods')->order('sort desc')
            ->where([
                'is_del'=>0,
                'cate_id'=>$id
            ])->select();
        return json(['code' => 200, 'data' => $goods_list, 'msg' => '获取成功']);
    }
}